package com.love_weinuo.ui.adapter;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.love_weinuo.R;
import com.love_weinuo.bean.DrugBean;
import com.love_weinuo.databinding.ItemDrugBinding;

import java.util.List;

/**
 * Created by Administrator on 2019/3/2.
 */

public class DrugAdapter extends RecyclerView.Adapter<BaseRecyclerViewHolder> {
    private List<DrugBean.ResultEntity.ResEntity> strings;
    private Context mcontext;
    OnItemClickListener mOnItemClickLitener;


    public DrugAdapter(Context context, List<DrugBean.ResultEntity.ResEntity> strings) {
        this.mcontext = context;
        this.strings = strings;
    }

    @Override
    public BaseRecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ItemDrugBinding functionBinding = DataBindingUtil.inflate(LayoutInflater.from(mcontext), R.layout.item_drug, parent, false);
        functionBinding.setAdapter(this);
        return new TourViewHolder(functionBinding);
    }

    @Override
    public void onBindViewHolder(final BaseRecyclerViewHolder holder, final int position) {
        holder.bindData(strings.get(position));
        TourViewHolder tv = (TourViewHolder) holder;

        if (mOnItemClickLitener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int pos = holder.getLayoutPosition();
                    mOnItemClickLitener.onItemClick(holder.itemView, pos);
                }
            });

            holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    int pos = holder.getLayoutPosition();
                    mOnItemClickLitener.onItemLongClick(holder.itemView, pos);
                    return false;
                }
            });
        }
    }

    public void setOnItemClickLitener(OnItemClickListener mOnItemClickLitener) {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }

    @Override
    public int getItemCount() {
        return strings.size();
    }

    public class TourViewHolder extends BaseRecyclerViewHolder<DrugBean.ResultEntity.ResEntity> {
        ItemDrugBinding functionBinding;

        public TourViewHolder(ItemDrugBinding dataBinding) {
            super(dataBinding.getRoot());
            functionBinding = dataBinding;
        }

        @Override
        public void bindData(DrugBean.ResultEntity.ResEntity data) {
            functionBinding.setBean(data);
        }
    }

    @Override
    public int getItemViewType(int position) {
        return strings.size();
    }


    public void toNext(View view, DrugBean.ResultEntity.ResEntity t) {

    }
}
